package com.sws.hmclient.controller;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sws.hmclient.common.BaseResponse;
import com.sws.hmclient.common.StatusCode;
import com.sws.hmclient.entity.Cpuinfo;
import com.sws.hmclient.entity.Meminfo;
import com.sws.hmclient.entity.Sysfileinfo;
import com.sws.hmclient.entity.Sysinfo;
import com.sws.hmclient.util.SystemInfoUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/process")
@Slf4j
public class ProcessesinfoController {

    //获取全部进程信息
    @RequestMapping("findAllProcessesinfo")
    public BaseResponse findAll() throws UnknownHostException {
        SystemInfoUtils sys=new SystemInfoUtils();
        List<com.sws.hmclient.entity.Processesinfo> processes = sys.getProcesses();
        BaseResponse response=new BaseResponse(StatusCode.Success);
        response.setCount(processes.size());
        response.setData(processes);
        return response;
    }

    //根据pid获取进程信息
    @RequestMapping("findProcessesinfobypid")
    public BaseResponse findAllbypid() throws UnknownHostException {
        SystemInfoUtils sys=new SystemInfoUtils();
        com.sws.hmclient.entity.Processesinfo processeByPod = sys.getProcesseByPod(4564);
        BaseResponse response=new BaseResponse(StatusCode.Success);
        response.setData(processeByPod);
        return response;
    }

    @RequestMapping(value = "/hello")
    @CrossOrigin(origins = "*")
    public String hello() {
        return "hello";
    }
}

